package com.hh.test.waitnotify;

public class Producer implements Runnable {

	public Producer(Stock stock) {
		super();
		this.stock = stock;
	}

	private Stock stock;

	public Stock getStock() {
		return stock;
	}

	public void setStock(Stock stock) {
		this.stock = stock;
	}

	public void run() {
		while (true) {
			try {
				Thread.sleep(700);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
			synchronized (stock) {
				stock.setNum(stock.getNum() + 1);
				System.out.println("生产了一个商品");
				System.out.println("剩余：" + stock.getNum());
				stock.notifyAll();
			}
		}
	}

}
